package com.wudgaby.spring.shiro.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

import com.wudgaby.spring.shiro.domain.User;

@Service
public class UserService {
    private static List<User> userList;
    {
        userList = new ArrayList<>();
        userList.add(new User(1, "admin", "123456", "11111", Arrays.asList("admin")));
        userList.add(new User(2, "wudgaby", "123456", "00000", Arrays.asList("admin","account")));
        userList.add(new User(3, "hkbird", "123456", "11111", Arrays.asList("account")));
    }

    private void print(){
        userList.forEach(user ->System.out.println(user));
    }

    public Optional<User> findByUserName(String userName){
        print();

        Optional<User> op = userList.stream().filter(user -> user.getUserName().equals(userName)).limit(1).findFirst();

        return op;
    }
}
